package hot100.logos81To90;

/**
 * @author logos
 * date 2025/7/18 11:20
 * @version v1.0
 * @Package hot100.logos81To90
 */
public class logos83 {

    /**
     * 83. 打家劫舍
     * https://leetcode.cn/problems/house-robber/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int rob(int[] nums) {
            int n = nums.length;
            if (n == 1) {
                return nums[0];
            }
            int a = nums[0];
            int b = Math.max(nums[0], nums[1]);
            int c = Math.max(a, b);
            for (int i = 2; i < n; i++) {
                c = Math.max(b, a + nums[i]);
                a = b;
                b = c;
            }
            return c;
        }
    }
}
